import axios from 'axios'

export default function (title, link, desc, img) {
  axios.get('https://share.fortrip.cn/Moxibustion/api/wechat', {
    params: { url: location.href }
  }).then(r => {
    window.wx.config({
      debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
      appId: 'wxeeccd27cfbf2766b', // 必填，公众号的唯一标识
      timestamp: r.data.data.timestamp, // 必填，生成签名的时间戳
      nonceStr: r.data.data.noncestr, // 必填，生成签名的随机串
      signature: r.data.data.signature, // 必填，签名
      jsApiList: ['onMenuShareTimeline', 'onMenuShareAppMessage', 'onMenuShareQQ', 'onMenuShareWeibo', 'onMenuShareQZone', 'updateAppMessageShareData', 'updateTimelineShareData', 'chooseImage'] // 必填，需要使用的JS接口列表  'updateAppMessageShareData', 'updateTimelineShareData',
    })

    window.wx.ready(function () {
      window.wx.onMenuShareAppMessage({
        title: title,
        desc: desc,
        link: link,
        imgUrl: img,
        success: function () {
        }
      })
      window.wx.onMenuShareTimeline({
        title: title,
        link: link,
        imgUrl: img,
        success: function () {
          // 设置成功
        }
      })
      window.wx.updateAppMessageShareData({
        title: title,
        desc: desc,
        link: link,
        imgUrl: img,
        success: function () {
        }
      })
      window.wx.updateTimelineShareData({
        title: title,
        link: link,
        imgUrl: img,
        success: function () {
          // 设置成功
        }
      })
    })
  }).catch(res => {
  })
}
